// 防抖动函数
function debounce(func, wait, immediate) {
  var timeout;
  return function () {
    var context = this,
      args = arguments;
    var later = function () {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, args);
  };
}

// 简单的节流函数
function throttle(func, wait, mustRun) {
  var timeout,
    startTime = new Date();

  return function () {
    var context = this,
      args = arguments,
      curTime = new Date();

    clearTimeout(timeout);
    // 如果达到了规定的触发时间间隔，触发 handler
    if (curTime - startTime >= mustRun) {
      func.apply(context, args);
      startTime = curTime;
      // 没达到触发间隔，重新设定定时器
    } else {
      timeout = setTimeout(func, wait);
    }
  };
}

// 判断移动端和pc端
/** 为 true 是移动端  为false pc端 */
function detectMobile() {
  return window.innerWidth <= 1024;
}

/** 获取字符串里的下标 */
function getIndex(val = "") {
  var _index = val.replace(/[^\d.]/g, "");
  return +_index;
}

function getParaByName(name) {
  var search = window.location.search;
  search = search.substr(1);
  if (typeof name === "undefined") return search;
  var searchArr = search.split("&");
  for (var i = 0; i < searchArr.length; i++) {
    var searchStr = searchArr[i];
    searchArr[i] = searchStr.split("=");
    if (searchArr[i][0] == name) {
      return searchStr.replace(name + "=", "");
    }
  }
  return "";
}
